bluetooth print settings

chengzhenyu 8 ans auparavant
Parent
Commettre
ade4ab81ae

+ 5 - 0
app/build.gradle

@@ -52,6 +52,11 @@ android {
52 52
             signingConfig signingConfigs.releaseConfig
53 53
         }
54 54
     }
55
+    sourceSets {
56
+        main {
57
+            aidl.srcDirs = ['src/main/java']
58
+        }
59
+    }
55 60
 
56 61
 }
57 62
 

+ 6 - 0
app/src/main/AndroidManifest.xml

@@ -81,6 +81,12 @@
81 81
             android:screenOrientation="portrait"></activity>
82 82
 
83 83
         <activity
84
+            android:name=".printer.PrinterSettingActivity"
85
+            android:configChanges="keyboardHidden|orientation|screenSize"
86
+            android:label="@string/app_name"
87
+            android:screenOrientation="portrait"></activity>
88
+
89
+        <activity
84 90
             android:name=".wxapi.WXEntryActivity"
85 91
             android:exported="true"
86 92
             android:launchMode="singleTop"

+ 24 - 0
app/src/main/java/ai/pai/lensman/printer/PrinterSettingActivity.java

@@ -0,0 +1,24 @@
1
+package ai.pai.lensman.printer;
2
+
3
+import android.os.Bundle;
4
+import android.support.annotation.Nullable;
5
+
6
+import ai.pai.lensman.R;
7
+import ai.pai.lensman.base.BaseActivity;
8
+import butterknife.ButterKnife;
9
+
10
+/**
11
+ * Created by chengzhenyu on 2016/8/31.
12
+ */
13
+
14
+public class PrinterSettingActivity extends BaseActivity {
15
+
16
+    @Override
17
+    protected void onCreate(@Nullable Bundle savedInstanceState) {
18
+        super.onCreate(savedInstanceState);
19
+        setContentView(R.layout.activity_printer_setting);
20
+        unbinder = ButterKnife.bind(this);
21
+    }
22
+
23
+
24
+}

+ 11 - 2
app/src/main/java/ai/pai/lensman/session/SessionActivity.java

@@ -15,12 +15,13 @@ import ai.pai.lensman.R;
15 15
 import ai.pai.lensman.base.BaseActivity;
16 16
 import ai.pai.lensman.bean.PhotoBean;
17 17
 import ai.pai.lensman.bean.SessionBean;
18
+import ai.pai.lensman.printer.PrinterSettingActivity;
18 19
 import ai.pai.lensman.qrcode.QRCaptureActivity;
19 20
 import butterknife.BindView;
20 21
 import butterknife.ButterKnife;
21 22
 import butterknife.OnClick;
22 23
 
23
-public class SessionActivity extends BaseActivity implements SessionContract.View {
24
+public class SessionActivity extends BaseActivity implements SessionContract.View ,View.OnClickListener{
24 25
 
25 26
     @BindView(R.id.icon_no_data)         View noPhotoLayout;
26 27
     @BindView(R.id.title_bar_middle_txt) TextView titleTextView;
@@ -93,7 +94,7 @@ public class SessionActivity extends BaseActivity implements SessionContract.Vie
93 94
 
94 95
     @OnClick(R.id.iv_qrcode)
95 96
     void showQRCodeForSession(){
96
-        new SessionQRPopup(this, sessionBean.sessionId).showPopupWindow();
97
+        new SessionQRPopup(this, sessionBean.sessionId,this).showPopupWindow();
97 98
     }
98 99
 
99 100
     @OnClick(R.id.title_bar_back_layout)
@@ -139,4 +140,12 @@ public class SessionActivity extends BaseActivity implements SessionContract.Vie
139 140
         }
140 141
     }
141 142
 
143
+    @Override
144
+    public void onClick(View view) {
145
+        if(view.getId()==R.id.btn_print_qr){
146
+            presenter.printQR();
147
+        }else if(view.getId()==R.id.tv_printer_set){
148
+            startActivity(new Intent(this, PrinterSettingActivity.class));
149
+        }
150
+    }
142 151
 }

+ 1 - 0
app/src/main/java/ai/pai/lensman/session/SessionContract.java

@@ -18,5 +18,6 @@ public class SessionContract {
18 18
 
19 19
     interface Presenter extends BasePresenter{
20 20
         void swipeToDeletePhoto(int index);
21
+        void printQR();
21 22
     }
22 23
 }

+ 59 - 8
app/src/main/java/ai/pai/lensman/session/SessionPresenter.java

@@ -3,19 +3,27 @@ package ai.pai.lensman.session;
3 3
 import android.content.ComponentName;
4 4
 import android.content.Context;
5 5
 import android.content.Intent;
6
+import android.content.ServiceConnection;
6 7
 import android.os.IBinder;
8
+import android.os.RemoteException;
9
+import android.util.Base64;
7 10
 import android.util.Log;
8 11
 
12
+import com.gprinter.aidl.GpService;
13
+import com.gprinter.command.EscCommand;
14
+import com.gprinter.command.GpCom;
15
+import com.gprinter.service.GpPrintService;
16
+
17
+import org.apache.commons.lang.ArrayUtils;
18
+
9 19
 import java.util.ArrayList;
20
+import java.util.Vector;
10 21
 
11 22
 import ai.pai.lensman.App;
12 23
 import ai.pai.lensman.bean.PhotoBean;
13 24
 import ai.pai.lensman.bean.SessionBean;
14 25
 import ai.pai.lensman.db.DBService;
15 26
 import ai.pai.lensman.service.UploadService;
16
-import android.content.ServiceConnection;
17
-import com.gprinter.aidl.GpService;
18
-
19 27
 
20 28
 
21 29
 public class SessionPresenter implements SessionContract.Presenter, SessionInteractor.SessionListener {
@@ -28,7 +36,7 @@ public class SessionPresenter implements SessionContract.Presenter, SessionInter
28 36
 
29 37
     private GpService mGpService = null;
30 38
     private PrinterServiceConnection conn = null;
31
-
39
+    private int mPrinterId = 0;
32 40
 
33 41
 
34 42
     public SessionPresenter(SessionBean sessionBean, SessionContract.View view) {
@@ -49,7 +57,7 @@ public class SessionPresenter implements SessionContract.Presenter, SessionInter
49 57
             }
50 58
         }
51 59
         interactor.startSession();
52
-        connection();
60
+        startAndBindPrintService();
53 61
     }
54 62
 
55 63
     @Override
@@ -75,7 +83,7 @@ public class SessionPresenter implements SessionContract.Presenter, SessionInter
75 83
 
76 84
     @Override
77 85
     public void onSessionPhotoCaptured(final PhotoBean bean) {
78
-        if(!isWorking){
86
+        if (!isWorking) {
79 87
             return;
80 88
         }
81 89
         DBService.getInstance().addPhotoBean(bean);
@@ -97,9 +105,51 @@ public class SessionPresenter implements SessionContract.Presenter, SessionInter
97 105
         interactor.deletePhoto(photoBean);
98 106
     }
99 107
 
100
-    private void connection() {
108
+    @Override
109
+    public void printQR() {
110
+        EscCommand esc = new EscCommand();
111
+        esc.addPrintAndFeedLines((byte) 3);
112
+        esc.addSelectJustification(EscCommand.JUSTIFICATION.CENTER);//设置打印居中
113
+        esc.addSelectPrintModes(EscCommand.FONT.FONTA, EscCommand.ENABLE.OFF, EscCommand.ENABLE.ON, EscCommand.ENABLE.ON, EscCommand.ENABLE.OFF);//设置为倍高倍宽
114
+        esc.addText("Sample\n");   //  打印文字
115
+        esc.addPrintAndLineFeed();
116
+
117
+		/*打印文字*/
118
+        esc.addSelectPrintModes(EscCommand.FONT.FONTA, EscCommand.ENABLE.OFF, EscCommand.ENABLE.OFF, EscCommand.ENABLE.OFF, EscCommand.ENABLE.OFF);//取消倍高倍宽
119
+        esc.addSelectJustification(EscCommand.JUSTIFICATION.LEFT);//设置打印左对齐
120
+        esc.addText("Welcome to use Paiai!\n");   //  打印文字
121
+
122
+		/*QRCode命令打印
123
+			此命令只在支持QRCode命令打印的机型才能使用。
124
+			在不支持二维码指令打印的机型上,则需要发送二维条码图片
125
+		*/
126
+        esc.addText("Print QRcode\n");   //  打印文字
127
+        esc.addSelectErrorCorrectionLevelForQRCode((byte) 0x31); //设置纠错等级
128
+        esc.addSelectSizeOfModuleForQRCode((byte) 3);//设置qrcode模块大小
129
+        esc.addStoreQRCodeData(sessionBean.sessionId);//设置qrcode内容
130
+        esc.addPrintQRCode();//打印QRCode
131
+        esc.addPrintAndLineFeed();
132
+
133
+        Vector<Byte> datas = esc.getCommand(); //发送数据
134
+        Byte[] Bytes = datas.toArray(new Byte[datas.size()]);
135
+        byte[] bytes = ArrayUtils.toPrimitive(Bytes);
136
+        String str = Base64.encodeToString(bytes, Base64.DEFAULT);
137
+        int rel;
138
+        try {
139
+            rel = mGpService.sendEscCommand(mPrinterId, str);
140
+            GpCom.ERROR_CODE r = GpCom.ERROR_CODE.values()[rel];
141
+            if (r != GpCom.ERROR_CODE.SUCCESS) {
142
+                sessionView.showToast( GpCom.getErrorText(r));
143
+            }
144
+        } catch (RemoteException e) {
145
+            e.printStackTrace();
146
+        }
147
+    }
148
+
149
+    private void startAndBindPrintService() {
150
+        Intent intent = new Intent(App.getAppContext(), GpPrintService.class);
151
+        App.getAppContext().startService(intent);
101 152
         conn = new PrinterServiceConnection();
102
-        Intent intent = new Intent("com.gprinter.aidl.GpPrintService");
103 153
         App.getAppContext().bindService(intent, conn, Context.BIND_AUTO_CREATE);
104 154
     }
105 155
 
@@ -115,4 +165,5 @@ public class SessionPresenter implements SessionContract.Presenter, SessionInter
115 165
             mGpService = GpService.Stub.asInterface(service);
116 166
         }
117 167
     }
168
+
118 169
 }

+ 14 - 2
app/src/main/java/ai/pai/lensman/session/SessionQRPopup.java

@@ -5,8 +5,10 @@ import android.content.Context;
5 5
 import android.view.LayoutInflater;
6 6
 import android.view.View;
7 7
 import android.view.animation.Animation;
8
+import android.widget.Button;
8 9
 import android.widget.ImageView;
9 10
 import android.widget.LinearLayout;
11
+import android.widget.TextView;
10 12
 
11 13
 import com.android.common.utils.DeviceUtils;
12 14
 import com.android.views.popup.BasePopupWindow;
@@ -19,15 +21,18 @@ import butterknife.ButterKnife;
19 21
 public class SessionQRPopup extends BasePopupWindow {
20 22
 
21 23
     private View popupView;
24
+    private Button printQRBtn;
22 25
     private ImageView groupQRImg;
26
+    private TextView printerSetText;
23 27
     private String groupId;
24 28
     private Context context;
29
+    private View.OnClickListener listener;
25 30
 
26
-
27
-    public SessionQRPopup(Activity context, String groupId) {
31
+    public SessionQRPopup(Activity context, String groupId,View.OnClickListener listener) {
28 32
         super(context);
29 33
         this.groupId = groupId;
30 34
         this.context = context;
35
+        this.listener = listener;
31 36
         init();
32 37
     }
33 38
 
@@ -45,10 +50,16 @@ public class SessionQRPopup extends BasePopupWindow {
45 50
     public View getPopupView() {
46 51
         popupView = LayoutInflater.from(mContext).inflate(R.layout.pop_session_qr, null);
47 52
         groupQRImg = ButterKnife.findById(popupView,R.id.iv_group_qrcode);
53
+        printQRBtn = ButterKnife.findById(popupView,R.id.btn_print_qr);
54
+        printerSetText = ButterKnife.findById(popupView,R.id.tv_printer_set);
55
+
48 56
         return popupView;
49 57
     }
50 58
 
51 59
     private void init(){
60
+        printQRBtn.setOnClickListener(listener);
61
+        printerSetText.setOnClickListener(listener);
62
+
52 63
         try{
53 64
             initQRImageSize();
54 65
             groupQRImg.setImageBitmap(QRCreateUtils.Create2DCode(UrlContainer.HOST_URL+groupId, DeviceUtils.dip2px(context,200)));
@@ -56,6 +67,7 @@ public class SessionQRPopup extends BasePopupWindow {
56 67
         }catch (Exception e){
57 68
             e.printStackTrace();
58 69
         }
70
+
59 71
     }
60 72
 
61 73
     @Override

BIN
app/src/main/res/drawable-hdpi/toggle_butt_close.png


BIN
app/src/main/res/drawable-hdpi/toggle_butt_on.png


+ 7 - 0
app/src/main/res/drawable/toggle_button_selector.xml

@@ -0,0 +1,7 @@
1
+<?xml version="1.0" encoding="utf-8"?>
2
+<selector xmlns:android="http://schemas.android.com/apk/res/android">
3
+
4
+    <item android:drawable="@drawable/toggle_butt_on" android:state_checked="true"/>
5
+    <item android:drawable="@drawable/toggle_butt_close" android:state_checked="false"/>
6
+
7
+</selector>

+ 191 - 0
app/src/main/res/layout/activity_printer_setting.xml

@@ -0,0 +1,191 @@
1
+<?xml version="1.0" encoding="utf-8"?>
2
+<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
3
+    android:layout_width="match_parent"
4
+    android:layout_height="match_parent"
5
+    android:background="@color/background_light_grey_color">
6
+
7
+    <LinearLayout
8
+        android:id="@+id/title_bar_with_back_btn"
9
+        android:layout_width="match_parent"
10
+        android:layout_height="@dimen/action_bar_height"
11
+        android:background="@color/colorPrimary"
12
+        android:orientation="horizontal">
13
+
14
+        <LinearLayout
15
+            android:id="@+id/title_bar_back_layout"
16
+            android:layout_width="70dp"
17
+            android:layout_height="match_parent"
18
+            android:gravity="center_vertical"
19
+            android:orientation="horizontal"
20
+            android:paddingLeft="12dp">
21
+
22
+            <ImageView
23
+                android:layout_width="32dp"
24
+                android:layout_height="32dp"
25
+                android:src="@drawable/back_selector" />
26
+
27
+        </LinearLayout>
28
+
29
+        <TextView
30
+            android:id="@+id/title_bar_middle_txt"
31
+            android:layout_width="0dp"
32
+            android:layout_height="match_parent"
33
+            android:layout_weight="1"
34
+            android:gravity="center"
35
+            android:paddingLeft="10dp"
36
+            android:paddingRight="10dp"
37
+            android:text="@string/printer_settings"
38
+            android:textColor="@color/text_white"
39
+            android:textSize="@dimen/action_bar_title_medium_text_size" />
40
+
41
+        <LinearLayout
42
+            android:id="@+id/title_bar_option_layout"
43
+            android:layout_width="70dp"
44
+            android:layout_height="match_parent"
45
+            android:gravity="center_vertical|right"
46
+            android:orientation="horizontal"
47
+            android:paddingRight="9dp"
48
+            android:visibility="invisible">
49
+
50
+
51
+            <ImageView
52
+                android:id="@+id/iv_options"
53
+                android:layout_width="32dp"
54
+                android:layout_height="32dp"
55
+                android:layout_marginLeft="6dp"
56
+                android:src="@drawable/option" />
57
+
58
+        </LinearLayout>
59
+
60
+    </LinearLayout>
61
+
62
+    <ScrollView
63
+        android:layout_width="match_parent"
64
+        android:layout_height="match_parent"
65
+        android:layout_below="@id/title_bar_with_back_btn">
66
+
67
+        <LinearLayout
68
+            android:layout_width="match_parent"
69
+            android:layout_height="wrap_content"
70
+            android:orientation="vertical">
71
+
72
+            <LinearLayout
73
+                android:layout_width="match_parent"
74
+                android:layout_height="38dp"
75
+                android:gravity="center_vertical"
76
+                android:orientation="horizontal"
77
+                android:paddingLeft="12dp">
78
+
79
+                <TextView
80
+                    android:layout_width="wrap_content"
81
+                    android:layout_height="wrap_content"
82
+                    android:text="@string/printer_status"
83
+                    android:textColor="@color/grey"
84
+                    android:textSize="14sp" />
85
+            </LinearLayout>
86
+
87
+
88
+            <LinearLayout
89
+                android:layout_width="match_parent"
90
+                android:layout_height="42dp"
91
+                android:background="@color/white"
92
+                android:gravity="center_vertical"
93
+                android:orientation="horizontal"
94
+                android:paddingLeft="12dp">
95
+
96
+                <TextView
97
+                    android:id="@+id/tv_printer_status"
98
+                    android:layout_width="wrap_content"
99
+                    android:layout_height="wrap_content"
100
+                    android:text="@string/query_processing"
101
+                    android:textColor="@color/dark_grey"
102
+                    android:textSize="16sp" />
103
+            </LinearLayout>
104
+
105
+            <LinearLayout
106
+                android:layout_width="match_parent"
107
+                android:layout_height="42dp"
108
+                android:layout_marginTop="1dp"
109
+                android:background="@color/white"
110
+                android:gravity="center_vertical"
111
+                android:orientation="horizontal"
112
+                android:paddingLeft="12dp">
113
+
114
+                <TextView
115
+                    android:id="@+id/tv_print_test"
116
+                    android:layout_width="wrap_content"
117
+                    android:layout_height="wrap_content"
118
+                    android:text="@string/print_test"
119
+                    android:textColor="@color/dark_grey"
120
+                    android:textSize="16sp" />
121
+            </LinearLayout>
122
+
123
+            <LinearLayout
124
+                android:layout_width="match_parent"
125
+                android:layout_height="38dp"
126
+                android:gravity="center_vertical"
127
+                android:orientation="horizontal"
128
+                android:paddingLeft="12dp">
129
+
130
+                <TextView
131
+                    android:layout_width="wrap_content"
132
+                    android:layout_height="wrap_content"
133
+                    android:text="@string/bluetooth_status"
134
+                    android:textColor="@color/grey"
135
+                    android:textSize="14sp" />
136
+            </LinearLayout>
137
+
138
+
139
+            <LinearLayout
140
+                android:layout_width="match_parent"
141
+                android:layout_height="42dp"
142
+                android:background="@color/white"
143
+                android:gravity="center_vertical"
144
+                android:orientation="horizontal"
145
+                android:paddingLeft="12dp">
146
+
147
+                <TextView
148
+                    android:id="@+id/tv_bluetooth_status"
149
+                    android:layout_width="0dp"
150
+                    android:layout_height="wrap_content"
151
+                    android:layout_weight="1"
152
+                    android:text="@string/bt_is_enabled"
153
+                    android:textColor="@color/dark_grey"
154
+                    android:textSize="16sp" />
155
+
156
+
157
+                <ToggleButton
158
+                    android:id="@+id/tb_bluetooth_switch"
159
+                    android:layout_width="56dp"
160
+                    android:layout_height="19dp"
161
+                    android:layout_marginRight="12dp"
162
+                    android:background="@drawable/toggle_button_selector"
163
+                    android:checked="true"
164
+                    android:gravity="center"
165
+                    android:textColor="@color/white"
166
+                    android:textOff="@null"
167
+                    android:textOn="@null" />
168
+
169
+            </LinearLayout>
170
+
171
+
172
+            <LinearLayout
173
+                android:layout_width="match_parent"
174
+                android:layout_height="38dp"
175
+                android:gravity="center_vertical"
176
+                android:orientation="horizontal"
177
+                android:paddingLeft="12dp">
178
+
179
+                <TextView
180
+                    android:layout_width="wrap_content"
181
+                    android:layout_height="wrap_content"
182
+                    android:text="@string/paired_devices"
183
+                    android:textColor="@color/grey"
184
+                    android:textSize="14sp" />
185
+            </LinearLayout>
186
+
187
+        </LinearLayout>
188
+    </ScrollView>
189
+
190
+
191
+</RelativeLayout>

+ 25 - 2
app/src/main/res/layout/pop_session_qr.xml

@@ -11,8 +11,8 @@
11 11
 
12 12
         <LinearLayout
13 13
             android:id="@+id/popup_anima"
14
-            android:layout_width="270dp"
15
-            android:layout_height="270dp"
14
+            android:layout_width="300dp"
15
+            android:layout_height="360dp"
16 16
             android:layout_centerInParent="true"
17 17
             android:gravity="center"
18 18
             android:background="@color/pop_bg_color"
@@ -34,6 +34,29 @@
34 34
                 android:textColor="@color/grey"
35 35
                 android:textSize="12sp" />
36 36
 
37
+            <Button
38
+                android:id="@+id/btn_print_qr"
39
+                android:layout_width="wrap_content"
40
+                android:layout_height="wrap_content"
41
+                android:paddingLeft="8dp"
42
+                android:paddingRight="8dp"
43
+                android:paddingBottom="5dp"
44
+                android:paddingTop="5dp"
45
+                android:textSize="14sp"
46
+                android:textColor="@color/dark_grey"
47
+                android:layout_marginTop="10dp"
48
+                android:text="@string/print_qr"/>
49
+
50
+            <TextView
51
+                android:id="@+id/tv_printer_set"
52
+                android:layout_marginTop="16dp"
53
+                android:padding="5dp"
54
+                android:layout_width="wrap_content"
55
+                android:layout_height="wrap_content"
56
+                android:text="@string/check_printer"
57
+                android:textColor="@color/light_blue"
58
+                android:textSize="12sp" />
59
+
37 60
         </LinearLayout>
38 61
 
39 62
     </RelativeLayout>

+ 28 - 0
app/src/main/res/values/strings.xml

@@ -58,4 +58,32 @@
58 58
     <string name="no_system_msg">暂无新系统消息</string>
59 59
 
60 60
     <string name="no_order_msg">暂无新购买消息</string>
61
+
62
+    <string name="print_qr">打印二维码</string>
63
+
64
+    <string name="check_bluetooth">请检查手机蓝牙是否开启</string>
65
+
66
+    <string name="check_printer">打印遇到问题了?去设置</string>
67
+
68
+    <string name="printer_settings">打印机设置</string>
69
+
70
+    <string name="printer_status">打印机状态</string>
71
+
72
+    <string name="query_processing">正在查询</string>
73
+
74
+    <string name="print_test">打印测试页</string>
75
+
76
+    <string name="bluetooth_status">蓝牙状态</string>
77
+
78
+    <string name="bt_is_enabled">蓝牙已打开</string>
79
+
80
+    <string name="bt_is_disabled">蓝牙已关闭</string>
81
+
82
+    <string name="connected_device">已连接设备</string>
83
+
84
+    <string name="discover_device">搜索设备</string>
85
+
86
+    <string name="paired_devices">已配对设备</string>
87
+
88
+    <string name="new_usable_devices">新可用设备</string>
61 89
 </resources>